/*****************************************************************************\
 *                            RESTRICTED RIGHTS LEGEND
 *
 *      Use, duplication, or disclosure by the Government is subject to
 *      restrictions as set forth in subparagraph (c) (1) (ii) of the Rights in
 *      Technical Data and Computer Software Clause at DFARS 252.227-7013.
 *
 *      The Board of Trustees of the University of Illinois
 *      109 Coble Hall
 *      801 South Wright Street
 *      Champaign, IL 61820-6242
 *
 *      File: Subject.cs
 *
 *      Authors: Erich Heine, David Rodgers, Denis Kholine, Derek Dagit,
 *      William H. Sanders, Klara Nahrstedt, Rakesh Bobba, Tim Yardley
 *      Creation Date: 2012
 *
 *      Copyright (c) 2012 William H. Sanders, Klara Nahrstedt, Erich Heine,
 *      Rakesh Bobba, Tim Yardley,
 *      and The Board of Trustees of the University of Illinois
 *      All rights reserved.
 * 
 *      No further use, distribution, or disclosure beyond internal development 
 *      project participants (Grid Protection Alliance and University of Illinois)
 *      is allowed.
 *
 \*****************************************************************************/

﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace SIEGate.Acl
{
    public abstract class Subject
    {
        public abstract ISet<Guid> GetIds();
    }


    public class SingleSubject : Subject
    {
        private readonly Guid id;

        public override ISet<Guid> GetIds()
        {
            ISet<Guid> toReturn = new HashSet<Guid>();
            toReturn.Add(this.id);
            return toReturn;
        }

        public SingleSubject()
        {
            throw new ArgumentException("SingleSubject must be initialized with a GUID.");
        }

        public SingleSubject(Guid id)
        {
            this.id = id;
        }
    }


    public class SubjectGroup : Subject
    {
        private readonly HashSet<Guid> ids;

        public string name
        {
            get;
            private set;
        }

        public override ISet<Guid> GetIds()
        {
            return this.ids;
        }

        public SubjectGroup()
        {
            throw new ArgumentException("SubjectGroup must be initialized with a GUID(s).");
        }

        public SubjectGroup(string name, params Guid[] ids)
        {
            if (ids.Count() < 1)
            {
                throw new ArgumentOutOfRangeException("SubjectGroup must be initialized with at least one GUID.");
            }

            this.ids = new HashSet<Guid>();

            foreach (Guid id in ids)
            {
                this.ids.Add(id);
            }

            this.name = name;
        }
    }
}
